package com.sgq.vue.controller.picture;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sgq.vue.entity.picture.Picture;
import com.sgq.vue.result.Result;
import com.sgq.vue.service.picture.PictureDustbinService;
import com.sgq.vue.vo.query.picture.PictureQueryVo;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 83778
 * @date: 2024-02-21 14:53
 * @desc:
 */
@Api(tags = "图片回收站")
@RestController
@RequestMapping("/api/picture/dustbin")
public class PictureDustbinController {

    @Autowired
    private PictureDustbinService pictureDustbinService;

    @GetMapping("/pageList")
    public Result pageList(PictureQueryVo pictureQueryVo){
        IPage<Picture> page  = pictureDustbinService.findIsNotRealDeletedByPage(pictureQueryVo);
        return Result.ok(page);
    }

    @GetMapping("/list")
    public Result list(){
        List<Picture> pictures  = pictureDustbinService.findIsNotRealDeletedList();
        return Result.ok(pictures);
    }

    /**
     * 恢复图片为未删除状态
     * @return
     */
    @PutMapping("/recover/{id}")
    public Result recoverPicture(@PathVariable Long id){
        Integer recover = pictureDustbinService.recover(id);
        return recover == 1 ? Result.ok("恢复成功") : Result.error().message("恢复失败");
    }

    /**
     * 彻底删除图片（包含oss和DB记录）
     * @return
     */
    @DeleteMapping("/finalDelete")
    public Result finalDelete(@RequestBody Picture picture){
        System.out.println("picture = " + picture);
        Integer integer = pictureDustbinService.finalDeleteById(picture);
        return Result.ok(integer);
    }
}
